<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib prefix="sys" uri="/WEB-INF/tld/sys.tld" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>经销商评级管理</title>
    <style type="text/css">
        .searchArea .fieldBox .label {
            width: 70px;
            overflow: hidden;
            white-space: nowrap;
            text-overflow: ellipsis;
        }
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">

<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
		<div tabid="tabA" title="经销商评级管理" lselected="true">
	    <div class="searchArea">
	        <form id="searchBar">
	            <div class="fieldset1 clearFix">
	                <div class="fieldBox">
	                    <div class="label">文件名称</div>
	                    <div class="field">
	                        <input name="fileNm" id="fileNm" type="text" class="ui-textbox" value="">
	                    </div>
	                </div>
	                <div class="fieldBox">
	                    <div class="label">上传人名称</div>
	                    <div class="field">
	                        <input name="uploadUsrNm" id="uploadUsrNm" type="text" class="ui-textbox" value="">
	                    </div>
	                </div>
	                <div class="clearFix"></div>
	                <div class="formBtns notRight">
	                    <span id="searchBtn" class="sq-button sq-button-round"></i>查询</span>
	                    <span id="clearBtn" class="sq-button sq-button-round"></i>清空</span>
	                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
	                </div>
	                <div class="fieldBox">
	                    <div class="field">
	                        <jsp:include page="../splCommonUlFilesRecUpload.jsp" flush="true">
	                            <jsp:param name="fileNum" value="1"/>
	                            <jsp:param name="filePath" value="${empty modulePath ? 'shop/splRateFile': modulePath }"/>
	                            <jsp:param name="upLoadCode" value="${empty upLoadCode ? 'SPL022': upLoadCode}"/>
	                            <jsp:param name="uploadSysCd" value="${uploadSysCd}"/>
	                            <jsp:param name="costomerPath" value="${costomerPath}"/>
	                            <jsp:param name="rootPath" value="${rootPath}"/>
	                        </jsp:include>
	                    </div>
	                    <div class="field">
	                        <span id="addBatchBtn" class="sq-button sq-button-round" onclick="importFile();">文件解析</span>
	                        <span id="downTempBtn" class="sq-button sq-button-round" onclick="downTemp();">下载模板</span>
	                    </div>
	                </div>
	            </div>
	        </form>
	    </div>
	
	    <div id="ligergrid1" class="sq-grid"></div>
	    </div>
	    <div tabid="tabB" title="挂靠公司评级管理">
				<iframe frameborder="0" name="tabB" id="tabB" src=""></iframe>
		</div>
	</div>
</div>

<script type="text/javascript">
    var grid = null;
    var callback = null;
    var _upLoadCode = '${upLoadCode}';
    var _dataTyp = '${dataTyp}';
    var pageInTab = null;
    var loadedTabs = [];
    var pageInApp = {
            flag: true
        };
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/splrate/parsetempfilerec/initList.do',
            method: 'get',
            columns: [
                {display: '记录主键', name: 'id', width: 200, align: 'left', enabledSort: false, hide: true},
                {display: '文件名称', name: 'fileNm', width: 200, align: 'left', enabledSort: false},
                {display: '上传时间', name: 'uploadDt', width: 100, align: 'center', enabledSort: false},
                {display: '上传人', name: 'uploadUsrNm', width: 100, align: 'center', enabledSort: false},
                {display: '状态', name: 'fileStsCdNm', width: 100, align: 'center', enabledSort: false},
                {display: '版本号', name: 'verNum', width: 150, align: 'center', enabledSort: false, hide: true},
                {
                    display: '是否最新', name: 'isNew', width: 100, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (value && value == '1') {
                            return "是";
                        } else {
                            return "否";
                        }
                    }
                },
                {display: '作废时间', name: 'obsoleteDt', width: 130, align: 'center', enabledSort: false},
                {
                    display: '操作', width: 120, align: 'center', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return "<a class='sq-button-hasicon' href='javascript:;' onclick='parseFileDetail(" + rowdata.id + ")'><i class='sqBtnIco_4'></i>详情</a> ";
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: true,
            frozen: false
        });
        grid.setHeight(100);

        $("#searchBar").ligerForm();

        $("#pageloading").hide();

        initTab();
        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
            var form = liger.get("searchBar");
            form.setData({  //重置select等特殊表单
                "fileNm": " ",
                "uploadUsrNm": " "
            });
        });

        callback = function () {
            grid.reload();
        };

        $("#file1").attr("accept", "application/vnd.ms-excel");
    });

    //初始化Tab
    function initTab() {
        pageInTab = $("#pageInTab").ligerTab({
            height: 'auto',
            contextmenu: false,
            minIframeHeight: GET_minIframeHeight(),
            onAfterSelectTabItem: function (tabid) {
                loadedTabs.push(tabid);
                switch (tabid) {
                    case "tabB":
                        pageInTab.setTabItemSrc(tabid, "<%=path%>/splrate/parsetempfilerec/toListPage.do?dataTyp=LNK");
                        break;
                }
                SetIframe_height();
            }
        });

        $.extend(true, pageInApp, {
            pageInTab: pageInTab
        });
    };

    function dialogCallback() {
        $.ligerDialog.hide();
        grid.reload();
    }

    //查询文件解析详情
    function parseFileDetail(_id) {
        var onCancel = function (item, Dialog) {
            Dialog.hide();
        };
        $.ligerDialog.SQopen({
            width: 1000,
            //height: 800,
            autoFixHeight: true,
            title: '解析信息',
            url: "<%=path%>/splrate/splraterelinfo/toListPage.do?parseFileRecId=" + _id,
            buttons: [
                {
                    text: "关闭", onclick: onCancel, type: 'cancel'
                }
            ]
        });
    }

    //批量导入
    function importFile() {
        //获取上传文件地址
        var files = getUploadResultParams();
        //var files=[{filePath:'C:/UPLOADTEST/capital/capFund/1472614427515.xls'}];
        if (files && files.length > 0) {
            var filePath = files[0].filePath;
            var fileExtension = filePath.substring(filePath.lastIndexOf('.') + 1);
            if (fileExtension != 'xls' && fileExtension != 'XLS') {
                $.ligerDialog.SQalert({content: "请上传.xls后缀的经销商评级文件", SQ_type: "warn"});
                return;
            }
            console.log("files ==" + JSON.stringify(files));
            //data["fileParams"] = JSON.stringify(files);
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {filePath: files[0].filePath, upLoadCode: _upLoadCode, fileParams: JSON.stringify(files),dataTyp:_dataTyp},
                url: '<%=path%>/splrate/parsetempfilerec/toImportSplRateData.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        event.stopPropagation();
                        clearUploadResultParams();//清除上传结果参数
                        grid.reload();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                },
                error: function () {
                    wait_dialog.close();
                    $.ligerDialog.SQalert({content: "经销商评级数据导入失败,请稍后重试", SQ_type: "error"});
                }
            });
        } else {
            $.ligerDialog.SQalert({content: "请先上传经销商评级数据文件", SQ_type: "warn"});
        }
    }

    //下载模板
    function downTemp() {
    	window.location.href = "<%=path%>/resource/template/spl/splRateTemp.xls";
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "——";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
        }
        return dateStr;
    }

    //格式化时间
    function renderDate2(rowdata, index, value) {
        var dateStr = "——";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }

</script>

</body>
</html>
